#include "mobilefilelistview.h"
#include <QDebug>
#include <QFileInfo>
#include <QDir>
#include <QPainter>

#include "fileinfo.h"

const int TAG_INFO = 100;
const int LIST_MODE_ICON_WIDTH = 32;
const int LIST_MODE_ICON_HEIGHT = 32;
const int ICON_MODE_MUSIC_ICON_WIDTH = 64;
const int ICON_MODE_MUSIC_ICON_HEIGHT = 64;
const int ICON_MODE_VIDEO_ICON_WIDTH = 96;
const int ICON_MODE_VIDEO_ICON_HEIGHT = 96;
const int ICON_MODE_VIDEO_GRID_HEIGHT = 124;
const int ICON_MODE_ITEM_WIDTH = 125;
const int ICON_MODE_MUSIC_GRID_HEIGHT = 132;
const int ICON_MODE_TOP_MARGIN = 28;
const int ICON_MODE_BOTTOM_MARGIN = 18;
const int ICON_MODE_SPACING = 26;
const int LIST_MODE_TOP_MARGIN = 12;
const int LIST_MODE_BOTTOM_MARGIN = 22;
const int LIST_MODE_ITEM_HEIGHT = 52;
const int LIST_MODE_SPACING = 4;
const int ICON_MODE_VIDEO_PLAY_BUTTON = 36;
const int ICON_MODE_VIDEO_PLAY_UPPER_LEFT_POINT = 30;
const int ICON_MODE_SELECT_BUTTON = 14;
const int LIST_MODE_GRID_HEIGHT = 56;

MobileFileListView::MobileFileListView(QWidget *parent) : QListView(parent)
{
    m_listModel = new QStandardItemModel(this);
    setModel(m_listModel);
    m_listDelefate = new MobileFileListDelegate(this);
    setItemDelegate(m_listDelefate);

    //自适应布局
    this->setResizeMode(QListView::Adjust);
    //列表中的图标不可拖动
    this->setMovement(QListView::Static);
    //去边框
    this->setFrameShape(QListView::NoFrame);
    //不可编辑
    this->setEditTriggers(QAbstractItemView::NoEditTriggers);
    //设置选中模式为选中行
    this->setSelectionBehavior(QAbstractItemView::SelectRows);
    //设置按ctrl键选中多个
    this->setSelectionMode(QAbstractItemView::ExtendedSelection);
    this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    this->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
    //设置项大小相同
    this->setUniformItemSizes(true);
    this->setContextMenuPolicy(Qt::CustomContextMenu);

    m_menu = new QMenu();
    initMenuAction();

    connect(this, &MobileFileListView::clicked, this, &MobileFileListView::slotClicked);
    connect(this, &MobileFileListView::doubleClicked, this, &MobileFileListView::slotDoubleClicked);
    connect(this, &MobileFileListView::customContextMenuRequested, this, &MobileFileListView::slotContextMenu);
}

MobileFileListView::~MobileFileListView()
{
    if (m_menu != nullptr) {
        delete m_menu;
        m_menu = nullptr;
    }

    if (m_openAction != nullptr) {
        delete m_openAction;
        m_openAction = nullptr;
    }
}

void MobileFileListView::initMenuAction()
{
    m_menu->clear();
    m_openAction = new QAction(tr("Open")); // Open打开
    connect(m_openAction, &QAction::triggered, this, &MobileFileListView::slotOpenTriggered);
}

void MobileFileListView::slotContextMenu(const QPoint &pos)
{
    if (!this->indexAt(pos).isValid()) {
        return;
    }

    Q_EMIT sigMouseRelease();

    m_menu->addAction(m_openAction);
    m_menu->popup(QCursor::pos());
}

void MobileFileListView::slotClicked(const QModelIndex &index)
{
    if (index.isValid()) {
        QList<FileInfo> fileList;
        this->selectAllNames(fileList);
        Q_EMIT sigSelectDataList(fileList);
        if (fileList.count() == 0) {
            Q_EMIT sigHideCopyToComputerWidget();
        } else {
            Q_EMIT sigShowCopyButton();
        }
    }
}

void MobileFileListView::slotDoubleClicked(const QModelIndex &index)
{
    FileInfo fileInfo = index.data(Qt::DisplayRole + TAG_INFO).value<FileInfo>();
    QString path = fileInfo.getPath();
    qInfo() << "double clicked" << path;
    Q_EMIT sigMenuFilePath(path);
}

void MobileFileListView::slotOpenTriggered()
{
    int row = this->currentIndex().row();
    QModelIndex index = this->model()->index(row, 0, QModelIndex());
    FileInfo fileInfo = index.data(Qt::DisplayRole + TAG_INFO).value<FileInfo>();
    QString path = fileInfo.getPath();
    qInfo() << "menu open" << path;
    Q_EMIT sigMenuFilePath(path);
}

void MobileFileListView::mousePressEvent(QMouseEvent *event)
{
    bool isListArea = this->indexAt(event->pos()).isValid();
    if (!isListArea) {
        if (QApplication::keyboardModifiers() != Qt::ControlModifier) {
            clearSelection();
            update();
        }
        if (event->source() != Qt::MouseEventSynthesizedByQt) {
            clearSelection();
            update();
        }
    }

    if (QApplication::keyboardModifiers() == Qt::NoModifier) {
        Q_EMIT sigMousePress(event);
    } else if (QApplication::keyboardModifiers() == Qt::ShiftModifier && event->button() == Qt::LeftButton) {
        Q_EMIT sigShiftMousePress(event);
    } else if (QApplication::keyboardModifiers() == Qt::ControlModifier && event->button() == Qt::LeftButton) {
        Q_EMIT sigCtrlMousePress(event);
    }
    QListView::mousePressEvent(event);
}

void MobileFileListView::mouseReleaseEvent(QMouseEvent *event)
{
    QListView::mouseReleaseEvent(event);

    Q_EMIT sigMouseRelease();
}

void MobileFileListView::keyPressEvent(QKeyEvent *event)
{
    QListView::keyPressEvent(event);
    if ((event->modifiers() == Qt::ControlModifier) && (event->key() == Qt::Key_A)) {
        QList<FileInfo> fileList;
        this->selectAllNames(fileList);
        Q_EMIT sigSelectDataList(fileList);
        Q_EMIT sigSelectAll();
    }
}

int MobileFileListView::getRow(QPoint point)
{
    return indexAt(point).row();
}

void MobileFileListView::selectRear(int row)
{
    for (int i = row; i < m_listModel->rowCount(); i++) {
        QModelIndex qindex = m_listModel->index(i, 0);
        selectionModel()->select(qindex, QItemSelectionModel::Select);
    }
}

void MobileFileListView::selectFront(int row)
{
    for (int i = row; i >= 0; i--) {
        QModelIndex qindex = m_listModel->index(i, 0);
        selectionModel()->select(qindex, QItemSelectionModel::Select);
    }
}

void MobileFileListView::selectExtent(int start, int end)
{
    for (int i = start; i <= end; i++) {
        QModelIndex qIndex = m_listModel->index(1, 0);
        selectionModel()->select(qIndex, QItemSelectionModel::Select);
    }
}

void MobileFileListView::selectAllNames(QList<FileInfo> &fileList)
{
    fileList.clear();
    for (QModelIndex index : selectionModel()->selectedIndexes()) {
        FileInfo fileInfo = index.data(Qt::DisplayRole + TAG_INFO).value<FileInfo>();
        fileList.append(fileInfo);
        if (fileInfo.type() == FileInfo::FILE_TYPE::TYPE_IMAGE) {
            QFileInfo file(fileInfo.getThumbnailPath());
            if (file.exists()) {
                QStandardItem *item = m_itemMap.find(fileInfo.getThumbnailPath()).value();
                QPixmap pixmap(fileInfo.getThumbnailPath());
                pixmap = pixmap.scaled(QSize(ICON_MODE_VIDEO_ICON_WIDTH, ICON_MODE_VIDEO_ICON_HEIGHT), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                QPixmap selectPixmap(":/png/image/icon_select.svg");
                selectPixmap = selectPixmap.scaled(QSize(ICON_MODE_SELECT_BUTTON, ICON_MODE_SELECT_BUTTON), Qt::KeepAspectRatio, Qt::SmoothTransformation);
                QPainter imagepainter(&pixmap);                                        //新建画板
                imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                imagepainter.drawPixmap((pixmap.width() - selectPixmap.width() - 8),
                                        (pixmap.height() - (pixmap.height() - 8)), selectPixmap);
                imagepainter.end();
                item->setIcon(pixmap);
            } else {
                QStandardItem *item = m_itemMap.find(fileInfo.getThumbnailPath()).value();
                QIcon icon = QIcon::fromTheme("image-x-generic");
                QPixmap pixmap(icon.pixmap(QSize(ICON_MODE_VIDEO_ICON_WIDTH, ICON_MODE_VIDEO_ICON_HEIGHT)));
                pixmap = pixmap.scaled(QSize(ICON_MODE_VIDEO_ICON_WIDTH, ICON_MODE_VIDEO_ICON_HEIGHT), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                QPixmap selectPixmap(":/png/image/icon_select.svg");
                selectPixmap = selectPixmap.scaled(QSize(ICON_MODE_SELECT_BUTTON, ICON_MODE_SELECT_BUTTON), Qt::KeepAspectRatio, Qt::SmoothTransformation);
                QPainter imagepainter(&pixmap);                                        //新建画板
                imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                imagepainter.drawPixmap((pixmap.width() - selectPixmap.width() - 8),
                                        (pixmap.height() - (pixmap.height() - 8)), selectPixmap);
                imagepainter.end();
                item->setIcon(pixmap);
            }
        } else if (fileInfo.type() == FileInfo::FILE_TYPE::TYPE_VIDEO) {
            QFileInfo file(fileInfo.getThumbnailPath());
            if (file.exists()) {
                QStandardItem *item = m_itemMap.find(fileInfo.getThumbnailPath()).value();
                QString localImagePath = QString("%1").arg(fileInfo.getThumbnailPath());
                QPixmap pixmap(localImagePath);
                pixmap = pixmap.scaled(QSize(ICON_MODE_VIDEO_ICON_WIDTH, ICON_MODE_VIDEO_ICON_HEIGHT), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                QPixmap playPixmap(":/png/image/play.png");
                playPixmap = playPixmap.scaled(QSize(ICON_MODE_VIDEO_PLAY_BUTTON, ICON_MODE_VIDEO_PLAY_BUTTON), Qt::KeepAspectRatio, Qt::SmoothTransformation);
                QPainter imagepainter(&pixmap);                                        //新建画板
                imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                        (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                imagepainter.end();

                QPixmap selectPixmap(":/png/image/icon_select.svg");
                selectPixmap = selectPixmap.scaled(QSize(ICON_MODE_SELECT_BUTTON, ICON_MODE_SELECT_BUTTON), Qt::KeepAspectRatio, Qt::SmoothTransformation);
                QPainter imagepainters(&pixmap);                                        //新建画板
                imagepainters.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                imagepainters.drawPixmap((pixmap.width() - selectPixmap.width() - 8),
                                        (pixmap.height() - (pixmap.height() - 8)), selectPixmap);
                imagepainters.end();
                item->setIcon(pixmap);
            } else {
                QStandardItem *item = m_itemMap.find(fileInfo.getThumbnailPath()).value();
                QIcon icon = QIcon(":/png/image/cover.png");
                QPixmap pixmap(icon.pixmap(QSize(ICON_MODE_VIDEO_ICON_WIDTH, ICON_MODE_VIDEO_ICON_HEIGHT)));
                pixmap = pixmap.scaled(QSize(ICON_MODE_VIDEO_ICON_WIDTH, ICON_MODE_VIDEO_ICON_HEIGHT), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                QPixmap playPixmap(":/png/image/play.png");
                playPixmap = playPixmap.scaled(QSize(ICON_MODE_VIDEO_PLAY_BUTTON, ICON_MODE_VIDEO_PLAY_BUTTON), Qt::KeepAspectRatio, Qt::SmoothTransformation);
                QPainter imagepainter(&pixmap);                                        //新建画板
                imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                        (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                imagepainter.end();

                QPixmap selectPixmap(":/png/image/icon_select.svg");
                selectPixmap = selectPixmap.scaled(QSize(ICON_MODE_SELECT_BUTTON, ICON_MODE_SELECT_BUTTON), Qt::KeepAspectRatio, Qt::SmoothTransformation);
                QPainter imagepainters(&pixmap);                                        //新建画板
                imagepainters.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                imagepainters.drawPixmap((pixmap.width() - selectPixmap.width() - 8),
                                        (pixmap.height() - (pixmap.height() - 8)), selectPixmap);
                imagepainters.end();
                item->setIcon(pixmap);
            }
        }
    }
    return;
}

void MobileFileListView::setViewHeight()
{
    updateViewHeight();
}

void MobileFileListView::setViewModeFlag(QListView::ViewMode mode, const QList<FileInfo> &listStruct)
{
    if (mode == QListView::IconMode) {
        for (int i = 0; i < listStruct.size(); i++) {
            if (listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_IMAGE
                || listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_VIDEO) {
                this->setIconSize(QSize(ICON_MODE_VIDEO_ICON_WIDTH, ICON_MODE_VIDEO_ICON_HEIGHT));
                //暂时设置边距0
                this->setSpacing(0);
                this->setGridSize(QSize(ICON_MODE_ITEM_WIDTH, ICON_MODE_VIDEO_GRID_HEIGHT));
            } else if (listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_AUDIO
                       || listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_TXT) {
                this->setIconSize(QSize(ICON_MODE_MUSIC_ICON_WIDTH, ICON_MODE_MUSIC_ICON_HEIGHT));
                this->setSpacing(0);
                this->setGridSize(QSize(ICON_MODE_ITEM_WIDTH, ICON_MODE_MUSIC_GRID_HEIGHT));
            }
        }
    } else {
        this->setIconSize(QSize(LIST_MODE_ICON_WIDTH, LIST_MODE_ICON_HEIGHT));
        this->setSpacing(0);
        this->setGridSize(QSize(this->width(), LIST_MODE_GRID_HEIGHT));
    }

    setViewMode(mode);

    if (this->viewMode() == QListView::IconMode) {
        for (int i = 0; i < listStruct.size(); i++) {
            if (listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_IMAGE
                || listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_VIDEO) {
                QModelIndex index = this->model()->index(i, 0, QModelIndex());
                this->model()->setData(index, QVariant(""), Qt::DisplayRole);
                this->model()->setData(index, QVariant(""), Qt::UserRole);
            } else {
                QModelIndex index = this->model()->index(i, 0, QModelIndex());
                QVariant meta;
                meta.setValue(listStruct.value(i).name());
                this->model()->setData(index, meta, Qt::DisplayRole);
                this->model()->setData(index, QVariant(""), Qt::UserRole);
            }
        }
    } else {
        for (int i = 0; i < listStruct.size(); i++) {
            QModelIndex index = this->model()->index(i, 0, QModelIndex());
            QVariant metaName;
            metaName.setValue(listStruct.value(i).name());
            QString sizeStr = getSize(listStruct.value(i).size());
            QVariant metaSize;
            metaSize.setValue(sizeStr);
            this->model()->setData(index, metaName, Qt::DisplayRole);
            this->model()->setData(index, metaSize, Qt::UserRole);
        }
    }

    if (this->viewMode() == QListView::IconMode) {
        setWidgetIconItemHeight();
    } else {
        setWidgetListItemHeight();
    }
}

QString MobileFileListView::getSize(qint64 sizeByte)
{
    QString text;
    if (sizeByte < 1024) {
        text = QString("%1B").arg(QString::number(sizeByte / 1.0, 'f', 1));
        return text;
    } else if (sizeByte < 1024 * 1024) {
        text = QString("%1KB").arg(QString::number(sizeByte / 1024.0, 'f', 1));
        return text;
    } else if (sizeByte < 1024 * 1024 * 1024) {
        text = QString("%1MB").arg(QString::number(sizeByte / 1024.0 / 1024.0, 'f', 1));
        return text;
    }
    text = QString("%1GB").arg(QString::number(sizeByte / 1024.0 / 1024.0 / 1024.0, 'f', 1));
    return text;
}

void MobileFileListView::updateViewHeight()
{
    if (this->viewMode() == QListView::IconMode) {
        setWidgetIconItemHeight();
    } else {
        setWidgetListItemHeight();
    }

    Q_EMIT signalSetResize(m_height);
}

void MobileFileListView::setWidgetIconItemHeight()
{
    int itemCount = 0;
    int count = this->width() / ICON_MODE_ITEM_WIDTH;
    if (m_listModel->rowCount() > 0) {
        if (m_listModel->rowCount() % count == 0) {
            itemCount = m_listModel->rowCount() / count;
        } else {
            itemCount = m_listModel->rowCount() / count + 1;
        }
    }
    if (m_listModel->rowCount() > 0) {
        if (itemCount == 1) {
            m_height = itemCount * ICON_MODE_VIDEO_ICON_HEIGHT + ICON_MODE_TOP_MARGIN + ICON_MODE_BOTTOM_MARGIN;
        } else {
            m_height = (itemCount - 1) * (ICON_MODE_VIDEO_ICON_HEIGHT + ICON_MODE_SPACING)
                    + ICON_MODE_VIDEO_ICON_HEIGHT + ICON_MODE_TOP_MARGIN + ICON_MODE_BOTTOM_MARGIN;
        }
    }
}

void MobileFileListView::setWidgetListItemHeight()
{
    int itemCount = m_listModel->rowCount();
    if (itemCount > 0) {
        if (itemCount == 1) {
            m_height = itemCount * LIST_MODE_ITEM_HEIGHT + LIST_MODE_TOP_MARGIN + LIST_MODE_BOTTOM_MARGIN;
        } else {
            m_height = (itemCount - 1) * (LIST_MODE_ITEM_HEIGHT + LIST_MODE_SPACING)
                    + LIST_MODE_ITEM_HEIGHT + LIST_MODE_TOP_MARGIN + LIST_MODE_BOTTOM_MARGIN;
        }
    }
}

void MobileFileListView::setResize()
{
    Q_EMIT signalSetResize(m_height);
}

void MobileFileListView::setTimeLineViewData(const QList<FileInfo> &listStruct, QMap<QString, QStandardItem *> &itemMap)
{
    m_listModel->clear();

    for (int i = 0; i < listStruct.size(); i++) {
        QStandardItem *item = new QStandardItem;
        QString thumbanilPath = listStruct.value(i).getThumbnailPath();
        m_itemPath.insert(listStruct.value(i).name(), listStruct.value(i).getPath());

        if (listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_IMAGE) { //图片
            QFileInfo file(listStruct.value(i).getThumbnailPath());
            if (file.exists()) {
                QString localImagePath = QString("%1").arg(listStruct.value(i).getThumbnailPath());
                QPixmap pixmap(localImagePath);
                pixmap = pixmap.scaled(QSize(ICON_MODE_VIDEO_ICON_WIDTH, ICON_MODE_VIDEO_ICON_HEIGHT), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                item->setIcon(pixmap);
            } else {
                item->setIcon(QIcon::fromTheme("image-x-generic"));
            }
            itemMap.insert(thumbanilPath, item);
            m_itemMap.insert(thumbanilPath, item);
        } else if (listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_VIDEO) { //视频
            QFileInfo file(listStruct.value(i).getThumbnailPath());
            if (file.exists()) {
                QString localImagePath = QString("%1").arg(listStruct.value(i).getThumbnailPath());
                QPixmap pixmap =
                    QIcon(localImagePath).pixmap(QSize(ICON_MODE_VIDEO_ICON_WIDTH, ICON_MODE_VIDEO_ICON_HEIGHT));
                pixmap = pixmap.scaled(QSize(ICON_MODE_VIDEO_ICON_WIDTH, ICON_MODE_VIDEO_ICON_HEIGHT),
                                       Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                QPixmap playPixmap(":/png/image/play.png");
                playPixmap = playPixmap.scaled(QSize(ICON_MODE_VIDEO_PLAY_BUTTON, ICON_MODE_VIDEO_PLAY_BUTTON),
                                               Qt::KeepAspectRatio, Qt::SmoothTransformation);
                QPainter imagepainter(&pixmap);                                        //新建画板
                imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                        (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                imagepainter.end();
                item->setIcon(pixmap);
            } else {
                QPixmap pixmap = QIcon(":/png/image/cover.png")
                                     .pixmap(QSize(ICON_MODE_VIDEO_ICON_WIDTH, ICON_MODE_VIDEO_ICON_HEIGHT));
                pixmap = pixmap.scaled(QSize(ICON_MODE_VIDEO_ICON_WIDTH, ICON_MODE_VIDEO_ICON_HEIGHT),
                                       Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                QPixmap playPixmap(":/png/image/play.png");
                playPixmap = playPixmap.scaled(QSize(ICON_MODE_VIDEO_PLAY_BUTTON, ICON_MODE_VIDEO_PLAY_BUTTON),
                                               Qt::KeepAspectRatio, Qt::SmoothTransformation);
                QPainter imagepainter(&pixmap);                                        //新建画板
                imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                        (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                imagepainter.end();
                item->setIcon(pixmap);
            }
            itemMap.insert(thumbanilPath, item);
            m_itemMap = itemMap;
        } else if (listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_AUDIO) { //音频
            item->setIcon(QIcon::fromTheme("audio-x-generic"));
            item->setData(listStruct.value(i).name(), Qt::DisplayRole);
        } else if (listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_TXT) { //文档
            item->setIcon(QIcon(QIcon::fromTheme("text")));
            item->setData(listStruct.value(i).name(), Qt::DisplayRole);
        } else if (listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_DOC) { // word
            item->setIcon(QIcon(QIcon::fromTheme("application-msword")));
            item->setData(listStruct.value(i).name(), Qt::DisplayRole);
        } else if (listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_EXCEL) { // excel
            item->setIcon(QIcon(QIcon::fromTheme("application-msexcel")));
            item->setData(listStruct.value(i).name(), Qt::DisplayRole);
        } else if (listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_PDF) { // pdf
            item->setIcon(QIcon(QIcon::fromTheme("application-pdf")));
            item->setData(listStruct.value(i).name(), Qt::DisplayRole);
        } else if (listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_PPTX) { // ppt
            item->setIcon(QIcon(QIcon::fromTheme("application-mspowerpoint")));
            item->setData(listStruct.value(i).name(), Qt::DisplayRole);
        } else if (listStruct.value(i).type() == FileInfo::FILE_TYPE::TYPE_ZIP) { // zip
            item->setIcon(QIcon(QIcon::fromTheme("application-archive-zip")));
            item->setData(listStruct.value(i).name(), Qt::DisplayRole);
        } else {
            item->setIcon(QIcon(QIcon::fromTheme("unknown")));
            item->setData(listStruct.value(i).name(), Qt::DisplayRole);
        }
        item->setData(listStruct.value(i), Qt::DisplayRole + TAG_INFO);
        item->setToolTip(listStruct.value(i).name());
        m_listModel->appendRow(item);
    }

    if (this->viewMode() == QListView::IconMode) {
        setWidgetIconItemHeight();
    } else {
        setWidgetListItemHeight();
    }
}
